#include "JumpProp.h"

#include "GameFramework/Character.h"


AJumpProp::AJumpProp()
{
	PrimaryActorTick . bCanEverTick = true;

	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));

	BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComponent"));
	BoxComponent -> SetupAttachment(GetRootComponent());
}

void AJumpProp::BeginPlay()
{
	Super::BeginPlay();
	BoxComponent -> OnComponentBeginOverlap . AddDynamic(this, &ThisClass::OnOverlapBegin);
}

void AJumpProp::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

void AJumpProp::OnOverlapBegin(
	UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
	UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
	bool bFromSweep, const FHitResult& SweepResult
)
{
	if (!bEnableJump) { return; }
	ACharacter* Character = Cast<ACharacter>(OtherActor);
	if (!Character) { return; }
	Character -> LaunchCharacter(FVector(0, 0, JumpZ), false, true);
}
